package flc.ast.fragment;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.chad.library.adapter.base.BaseQuickAdapter;

import java.util.ArrayList;
import java.util.List;

import flc.ast.R;
import flc.ast.activity.AddDrawActivity;
import flc.ast.activity.DrawActivity;
import flc.ast.activity.DrawRecordActivity;
import flc.ast.activity.DrawTempActivity;
import flc.ast.activity.SelPicActivity;
import flc.ast.adapter.DrawTempAdapter;
import flc.ast.bean.MyDrawTempBean;
import flc.ast.databinding.FragmentDrawBinding;
import stark.common.basic.base.BaseNoModelFragment;
import stark.common.basic.event.EventStatProxy;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link DrawFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class DrawFragment extends BaseNoModelFragment<FragmentDrawBinding> {

    private DrawTempAdapter tempAdapter;

    @Override
    protected int onCreate() {
        return R.layout.fragment_draw;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(getActivity(), mDataBinding.event1Container);
        EventStatProxy.getInstance().statEvent5(getActivity(), mDataBinding.event5Container);

        mDataBinding.ivDrawRecord.setOnClickListener(this);
        mDataBinding.ivDrawImport.setOnClickListener(this);
        mDataBinding.ivAddDraw.setOnClickListener(this);
        mDataBinding.ivDrawTempMore.setOnClickListener(this);

        mDataBinding.rvTemplateList.setLayoutManager(new GridLayoutManager(mContext, 3));
        tempAdapter = new DrawTempAdapter();
        mDataBinding.rvTemplateList.setAdapter(tempAdapter);
        tempAdapter.setOnItemClickListener(this);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.ivDrawRecord://历史记录
                startActivity(DrawRecordActivity.class);
                break;
            case R.id.ivDrawImport://导入图片
                startActivity(SelPicActivity.class);
                break;
            case R.id.ivAddDraw://新建画布
                startActivity(AddDrawActivity.class);
                break;
            case R.id.ivDrawTempMore://查看更多
                startActivity(DrawTempActivity.class);
                break;
        }
    }

    @Override
    protected void onItemClickCallback(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
        gotoDraw(tempAdapter.getItem(position).getImg());
    }

    @Override
    protected void initData() {
        List<MyDrawTempBean> listTemp = new ArrayList<>();
        listTemp.add(new MyDrawTempBean(R.drawable.mb_1a, R.drawable.mb_1));
        listTemp.add(new MyDrawTempBean(R.drawable.mb_2a, R.drawable.mb_2));
        listTemp.add(new MyDrawTempBean(R.drawable.mb_3a, R.drawable.mb_3));
        listTemp.add(new MyDrawTempBean(R.drawable.mb_4a, R.drawable.mb_4));
        listTemp.add(new MyDrawTempBean(R.drawable.mb_5a, R.drawable.mb_5));
        listTemp.add(new MyDrawTempBean(R.drawable.mb_6a, R.drawable.mb_6));
        listTemp.add(new MyDrawTempBean(R.drawable.mb_7a, R.drawable.mb_7));
        listTemp.add(new MyDrawTempBean(R.drawable.mb_8a, R.drawable.mb_8));
        listTemp.add(new MyDrawTempBean(R.drawable.mb_9a, R.drawable.mb_9));
        tempAdapter.setList(listTemp);
    }

    //去到绘画界面
    private void gotoDraw(int img) {
        DrawActivity.kind = 1;
        DrawActivity.selImg = img;
        startActivity(DrawActivity.class);
    }

}